package com.ssy.lingxi.common.response;

import javax.validation.constraints.NotEmpty;

/**
 * 统一返回成功数据模型
 */
public class WrapperSuccess<T> {

    /**
     * 状态码
     */
    @NotEmpty
    private int code;
    /**
     * 数据体
     */
    @NotEmpty
    private T data;

    public WrapperSuccess() {
    }

    public static <T> WrapperSuccess<T> success() {
        ResponseCode responseCode = ResponseCode.SUCCESS;
        return new WrapperSuccess<>(responseCode.getCode(), null);
    }

    public static <T> WrapperSuccess<T> success(T data) {
        ResponseCode responseCode = ResponseCode.SUCCESS;
        return new WrapperSuccess<>(responseCode.getCode(), data);
    }

    private WrapperSuccess(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
